#include "stdafx.h"
#include "i_UIcompote_imp.h"

i_UIcompte_imp::i_UIcompte_imp():
m_active(false)
{

}

i_UIcompte_imp::~i_UIcompte_imp()
{
	for (EffectCollIt it=m_effects.begin();it!=m_effects.end();++it)
	{
		if (*it)
		{
			delete (*it);
			(*it)=0;
		}
	}
	m_effects.clear();

	for (ElementCollIt it=m_elements.begin();it!=m_elements.end();++it)
	{
		if ((*it).second)
		{
			delete (*it).second;
			(*it).second=0;
		}
	}
	m_elements.clear();

}

bool i_UIcompte_imp::add_element(std::string _name, i_UIelement* _element )
{
	ElementCollIt it=m_elements.find(_name);
	if (it==m_elements.end())
	{
		if (_element)
		{
			m_elements.insert(std::make_pair(_name,_element));
			return true;
		}
	}
	return false;

}

bool i_UIcompte_imp::add_effect( i_UIeffect* _effect )
{
	if (_effect)
	{
		m_effects.push_back(_effect);
		return true;
	}
	return false;

}

bool i_UIcompte_imp::remove_element( std::string _name )
{
	ElementCollIt it=m_elements.find(_name);
	if (it!=m_elements.end())
	{
		if ((*it).second)
		{
			delete (*it).second;
			(*it).second=0;
		}
		m_elements.erase(it);
		return true;

	}
	return false;

}